import platform
import pymysql
from .config import *

# 汇总
def environment():
    os()
    mysql()
    


# 操作系统检测
def os():
    print(f'\n当前操作系统:'+platform.system())


# 数据库
def mysql():
    try:
        # 建立连接
        connection = pymysql.connect(
            host=HOSTNAME,
            user=USERNAME,
            password=PASSWORD,
            database=DATABASE
        )
        print("\n数据库连接成功\n")
    except pymysql.MySQLError as e:
        print(f"\n数据库连接失败，请检查数据库是否开启和配置是否正确\n{e}\n")
    finally:
        if 'connection' in locals() and connection.open:
            connection.close()